package leecode

func statisticalResult(arrayA []int) (result []int) {
	//数组中存在0的特殊情况
	temp := 1
	flag := 1
	zeroCount := 0
	for i := 0; i < len(arrayA); i++ {
		if arrayA[i] == 0 {
			zeroCount++
			flag = 0 //存在
			if zeroCount >= 2 {
				res := make([]int, len(arrayA))
				return res
			}
			continue
		}
		temp = temp * arrayA[i]
	}
	if flag == 0 {
		for i := 0; i < len(arrayA); i++ {
			if arrayA[i] == 0 {
				result = append(result, temp)
			} else {
				result = append(result, 0)
			}
		}
		return result
	}
	prefix := make([]int, len(arrayA)+1) //前缀积
	prefix[0] = 1
	for i := 0; i < len(arrayA); i++ {
		prefix[i+1] = prefix[i] * arrayA[i]
	}
	//求结果
	for i := 0; i < len(arrayA); i++ {
		//逐个排除
		result = append(result, prefix[len(prefix)-1]/arrayA[i])
	}
	return
}
